import random
import pyperclip
from pymouse import *
from pykeyboard import *
import time

m = PyMouse()
k = PyKeyboard()

input = [182, 617]
input1 = [182, 390]
ok = [150, 470]
run = [210, 705]
ks = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
      'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J',
      'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']


def copy_code():
    s = '2022'
    index = random.sample(range(0, 62), 8)
    for i in index:
        s += ks[i]
    pyperclip.copy(s)
    keyboard = PyKeyboard()
    keyboard.press_key(keyboard.control_key)  # 按下Ctrl键
    keyboard.tap_key('V')  # 点击V键
    keyboard.release_key(keyboard.control_key)  # 松开Ctrl键


def one():
    m.click(input[0], input[1], 1, 1)
    time.sleep(0.03)
    m.click(input1[0], input1[1], 1, 1)
    # for_code()
    copy_code()
    time.sleep(0.03)
    m.click(ok[0], ok[1], 1, 1)
    time.sleep(0.03)
    m.click(run[0], run[1], 1, 1)
    time.sleep(0.03)


def for_code():
    k.tap_key('2')
    time.sleep(0.005)
    k.tap_key('0')
    time.sleep(0.005)
    k.tap_key('2')
    time.sleep(0.005)
    k.tap_key('2')
    time.sleep(0.005)
    index = random.sample(range(0, 62), 8)
    for i in index:
        k.tap_key(ks[i])
        time.sleep(0.005)


ts1 = 5
ts = 10000
t = 0
k.press_keys([k.windows_l_key, '1'])
k.release_key(k.windows_l_key)
k.release_key('1')
time.sleep(0.003)
while t < ts:
    t += 1
    one()
    time.sleep(5)
    if t == ts:
        print(t)
        t = 0
